package com.teemo.dp.singleton.demo9;


/**
 * @author Teemo
 */
public class Washer2 {
    private Washer2() {
        System.out.println("washer init");
        if (WasherHolder.washer != null){
            throw new RuntimeException("单例模式不允许创建多个实例");
        }
    }

    private static class WasherHolder {
        private static Washer2 washer = new Washer2();
    }

    public static Washer2 getInstance() {
        System.out.println("获取实例");
        return Washer2.WasherHolder.washer;
    }

    public void wash() {
        System.out.println("wash");
    }
}
